package com.ruoyi.web.controller.other;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.community.domain.HouseCommunityT;
import com.ruoyi.community.service.IHouseCommunityTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 社区Controller
 *
 * @author ruoyi
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/other/community")
public class HouseCommunityTController extends BaseController
{
    @Autowired
    private IHouseCommunityTService houseCommunityTService;

    /**s
     * 查询社区列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseCommunityT houseCommunityT)
    {
        startPage();
        List<HouseCommunityT> list = houseCommunityTService.selectHouseCommunityTList(houseCommunityT);
        return getDataTable(list);
    }

    /**
     * 导出社区列表
     */
    @Log(title = "社区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseCommunityT houseCommunityT)
    {
        List<HouseCommunityT> list = houseCommunityTService.selectHouseCommunityTList(houseCommunityT);
        ExcelUtil<HouseCommunityT> util = new ExcelUtil<HouseCommunityT>(HouseCommunityT.class);
        util.exportExcel(response, list, "社区数据");
    }

    /**
     * 获取社区详细信息
     */
     @GetMapping(value = "/{communityId}")
    public AjaxResult getInfo(@PathVariable("communityId") Long communityId)
    {
        return AjaxResult.success(houseCommunityTService.selectHouseCommunityTByCommunityId(communityId));
    }

    /**
     * 新增社区
     */
     @Log(title = "社区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseCommunityT houseCommunityT)
    {
        houseCommunityT.setCreater(getUsername());
        return toAjax(houseCommunityTService.insertHouseCommunityT(houseCommunityT));
    }

    /**
     * 修改社区
     */
    @Log(title = "社区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseCommunityT houseCommunityT)
    {
        return toAjax(houseCommunityTService.updateHouseCommunityT(houseCommunityT));
    }

    /**
     * 删除社区
     */
   @Log(title = "社区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{communityIds}")
    public AjaxResult remove(@PathVariable Long[] communityIds)
    {
        return toAjax(houseCommunityTService.deleteHouseCommunityTByCommunityIds(communityIds));
    }
}
